import React from 'react'
import store from "../../store/store"
import { incrementAction,decrementAction ,waitDecrementAction} from '../../store/actions/countAction'
import { getMovieAction } from '../../store/actions/movieAction'
export default function Count() {
  const { count } = store.getState().count;
  const { movie } = store.getState().movie

  const incrementHandle = () => {
    store.dispatch(incrementAction())
  }

  const decreamentHandle = () => {
    store.dispatch(decrementAction())
  }

  const ifOddDecrementHandle = () => {
    if (count%2!==0) {
      store.dispatch(incrementAction())
    }
  }

  const waitDecrementHandle = () => {
    store.dispatch(waitDecrementAction())
  }

const getMovieHandle=()=>{
  store.dispatch(getMovieAction())
}
  return (
    <div>
      <h1>我是Count组件 我的值是{count}</h1>
      <h1>电影的个数是{movie.length}</h1>
      <button onClick={getMovieHandle}>点击查询电影</button>
      <div>
        <button onClick={incrementHandle}>累加</button>
        <button onClick={decreamentHandle}>累减</button>
        <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
        <button onClick={waitDecrementHandle}>等2s再加1</button>
      </div>
      {movie.map(item=>{
        return <li key={item.albumId}>{item.name}</li>
      })}
    </div>
  )
}
